package com.sddongyun.config;

import com.sddongyun.filter.HisServletFilter;
import com.sddongyun.filter.QrpayServletFilter;
import com.sddongyun.filter.ReplaceStreamFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.DelegatingFilterProxy;

import javax.servlet.Filter;

@Configuration
public class FilterConfiguration {
    /**
     * 替换 request 、 response 为包装类
     * @return
     */
//    @Bean
//    public FilterRegistrationBean replaceStreamFilter() {
////        return new ReplaceStreamFilter();
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        registration.setFilter(new ReplaceStreamFilter());
//        registration.addUrlPatterns("/yb/*");
//        registration.setName("replaceStreamFilter");
//        registration.setOrder(3);
//        return registration;
//    }
    @Bean
    public Filter generalFilter() {
        return new QrpayServletFilter();
    }

    @Bean
    public Filter hisFilter() {
        return new HisServletFilter();
    }
    @Bean
    public Filter ybFilter() {
        return new ReplaceStreamFilter();
    }
    @Bean
    public FilterRegistrationBean uploadFilterRegistration1() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new DelegatingFilterProxy("ybFilter"));
        registration.addUrlPatterns("/yb/*");
        registration.setName("ybFilter");
        registration.setOrder(1);
        return registration;
    }
    @Bean
    public FilterRegistrationBean uploadFilterRegistration2() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new DelegatingFilterProxy("hisFilter"));
        registration.addUrlPatterns("/his/*");
        registration.setName("hisFilter");
        registration.setOrder(1);
        return registration;
    }
    @Bean
    public FilterRegistrationBean uploadFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new DelegatingFilterProxy("generalFilter"));
        registration.addUrlPatterns("/qrpay/*");
        registration.setName("generalFilter");
        registration.setOrder(2);
        return registration;
    }
}
